/*
 * @Author: moeWang
 * @Date: 2022-03-07 10:28:00
 * @LastEditTime: 2022-03-07 16:46:04
 * @LastEditors: moeWang
 * @Description:
 * @FilePath: \nest-web\src\logical\login-log\entity\loginLog.entity.ts
 */

import { ApiProperty } from '@nestjs/swagger';
import * as moment from 'moment';
import {
  Column,
  Comment,
  DataType,
  Model,
  PrimaryKey,
  Table,
} from 'sequelize-typescript';

@Table({
  tableName: 'rp_login_log',
  timestamps: false,
  comment: '登录日志表',
})
export class LoginLogEntity extends Model<LoginLogEntity> {
  @ApiProperty({ description: 'id' })
  @Comment('id')
  @PrimaryKey
  @Column({
    primaryKey: true,
    type: DataType.BIGINT,
  })
  id: string;

  @ApiProperty({ description: 'userid' })
  @Comment('userid')
  @Column({
    type: DataType.BIGINT,

    field: 'user_id',
  })
  userId: string;

  @Column({
    type: DataType.CHAR,
  })
  account: string;
  @Column({
    type: DataType.CHAR,

    field: 'user_name',
  })
  userName: string;

  @ApiProperty({ description: '登录时间' })
  @Comment('登录时间')
  @Column({
    get() {
      const date = this.getDataValue('loginTime');
      return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '';
    },

    field: 'login_time',
  })
  loginTime: Date;

  @Column({
    type: DataType.CHAR(3),

    field: 'login_status',
  })
  loginStatus: string;
  @Column({
    type: DataType.CHAR,

    field: 'error_message',
  })
  errorMessage: string;
}
